home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 05.zip / BS1 part 5 / IM_3.adf / Exec / piarc.LZH / animrd.rexx < prev    next >
OS/2 REXX Batch file  |  1992-05-22  |  6KB  |  247 lines

  1. /*
  2.  * animr.rexx
  3.  *
  4.  *  Written by: Pete Patterson
  5.  * Last Update: May 28, 1992
  6.  *         For: Black Belt Systems image processing series IM, IM F/c, and IP.
  7.  * ---------------------------------------------------------------------------
  8.  *    Revision: 1.1
  9.  *
  10.  *    1.0 - Jan  7/92 Initial releas
  11.  *    1.1 - May 28/92 Fixed refresh bug in AREXX script
  12.  *                    Fixed file recognition bug in ANIMRD executable
  13.  */
  14.  
  15. parse arg afname aframe
  16.  
  17. /*
  18.  * open rexxsupport.library -- needed for some functions
  19.  */
  20. if ~show('L',"rexxsupport.library") then do
  21.   if addlib('rexxsupport.library',0,-30,0) then do
  22.       /* everything's ok */
  23.     end;
  24.   else do
  25.     say 'We Have A Library Problem, Unable To Load "rexxsupport.library"';
  26.     say 'Cannot operate animr.rexx without this library - sorry!';
  27.     exit 10;
  28.     end;
  29.   end;
  30.  
  31. /*
  32.  * This will automatically direct the script to the proper
  33.  * software, if it is running.
  34.  */
  35. prtnme = 'IP_Port'; /* assume Image Professional */
  36. if show('P','IP_Port') = 0 then do
  37.   if show('P','IM_Port') = 0 then do
  38.     say "Can't find image processor's ARexx port!!!"; /* not running? */
  39.     say "This script requires IP, IM or IM F/c to run!";
  40.     exit(20);
  41.     end;
  42.   else do
  43.     prtnme = 'IM_Port'; /* That's the thing about assumptions... */
  44.     end;                 /* We make em, user's break em.          */
  45.   end;
  46.  
  47. options;
  48. address;
  49.  
  50.   prevpath = 'ram:'; /* put user in ram to start with... */
  51.  
  52.   if show('C',animpath) = 1 then do
  53.     prevpath = getclip(animpath);
  54.     end;
  55.  
  56.   address(prtnme);
  57.   options results;
  58.   'current';
  59.   bufdata = result; /* get name of buffer, if there is one */
  60.   parse var bufdata bname ',' bnum ',' bx ',' by ',' btot ',' bmem ',' bparname ',' bparnum;
  61.   if bname ~= '<none>' then do
  62.     bufname = bname;
  63.     end;
  64.   if (length(bufname) > 4) then do
  65.     epos = pos('.anim',bufname,length(bufname)-4);
  66.     if epos ~= 0 then do
  67.       bufname = left(bufname,epos-1)
  68.       end
  69.     end;
  70.   if (afname = "") then do
  71.     'filerequest "'||prevpath||'","'||bufname||'",".anim","Load anim"';
  72.     animfile = result;
  73.     options;
  74.  
  75.     if animfile = 'FR_CANCELLED' then do
  76.       address(prtnme);
  77.       'imtofront';
  78.       exit 0;
  79.       end;
  80.   end;
  81.   else do
  82.     animfile = afname;
  83.   end;
  84.  
  85.   animfile = expandfilename(animfile);
  86.   thispath = gimmepath(animfile);
  87.   call setclip(animpath,thispath);
  88.  
  89.   address command 'cmpi:ANIMRD c "'||animfile||'"';
  90.   if rc ~= 0 then do
  91.     address(prtnme);
  92.     'message "Cannot read '||animfile||'"';
  93.     exit 0; /* this is not a proper anim file */
  94.     end;
  95.  
  96.   call open(fhandle,'ram:IP_ANIMRD.tmp','read');      /* open the file */
  97.   rstring = readln(fhandle);
  98.   call close(fhandle);                     /* close the file    */
  99.  
  100.   address command 'c:delete >nil: ram:IP_ANIMRD.tmp';
  101.   
  102.   parse var rstring width '/' height '/' frames '/' type
  103.  
  104.   if height < 0 then do
  105.     'message "Bad Height: '||height||'"';
  106.     exit 0;
  107.     end;
  108.  
  109.   if height > 32767 then do
  110.     'message "Bad Height: '||height||'"';
  111.     exit 0;
  112.     end;
  113.  
  114.   if width < 0 then do
  115.     'message "Bad Width: '||width||'"';
  116.     exit 0;
  117.     end;
  118.  
  119.   if width > 32767 then do
  120.     'message "Bad Width: '||width||'"';
  121.     exit 0;
  122.     end;
  123.  
  124.   if frames < 0 then do
  125.     'message "# Frames is negative: '||width||'"';
  126.     exit 0;
  127.     end;
  128.  
  129.   if frames > 32767 then do
  130.     'message "Too many frames: '||width||'"';
  131.     exit 0;
  132.     end;
  133.   address(prtnme);
  134.  
  135.   if (aframe = "") then do
  136.     options results;
  137.     'askprop '||'"Load which frame?" 1 1 '||frames
  138.     frame = result;
  139.     options;
  140.   end;
  141.   else do
  142.     frame = aframe;
  143.   end;
  144.  
  145.   'imtofront'; /* show user the IM screen */
  146.   /* is there already a primary buffer??? */
  147.   options results;
  148.   'current';
  149.   bufdata = result;
  150.   options;
  151.  
  152.   parse var bufdata bname ',' bnum ',' bx ',' by ',' btot ',' bmem ',' bparname ',' bparnum
  153.   if bname ~= '<none>' then do
  154.     address(prtnme);
  155.   options results;
  156.   'askyn '||'"Replace Primary ['||bname||']" "New As Primary"'
  157.   prefs = result;
  158.   options;
  159.   address;
  160.   if prefs = 0 then do
  161.     address(prtnme);
  162.     'killbuff '||bnum; /* this kills the Primary Buffer */
  163.     address;
  164.     end;
  165.   end;
  166.  
  167.   /* New buffer is created at current resolution */
  168.   address(prtnme);
  169.   'autoredraw 0';
  170.   'newbuf '||width||' '||height;
  171.   options results;
  172.   'current';
  173.   bufdata = result;
  174.   options;
  175.   parse var bufdata bname ',' bnum ',' bx ',' by ',' btot ',' bmem ',' bparname ',' bparnum
  176.   'rename '||bnum||' 'gxname;
  177.   address;
  178.  
  179.   address(prtnme);
  180.   options results;
  181.   'jackin';
  182.   jackadr = result;
  183.   options;
  184.  
  185.   'wbtofront';
  186.   address command 'cmpi:ANIMRD d'||jackadr||' '||frame||' '||type||' "'||animfile||'"';
  187.  
  188.   address(prtnme);
  189.   'imtofront';
  190.   'redraw';
  191.   'autoredraw 1';
  192.   address;
  193.  
  194.   exit 0;
  195.  
  196. /*
  197.  * gimmepath
  198.  *
  199.  * This takes the provided argument and sucks the path out of it, then
  200.  * returns that path to the caller, sans file name.
  201.  */
  202. gimmepath:
  203.   arg fullnamegx;
  204.     tempgx = reverse(fullnamegx);
  205.     lengx = length(fullnamegx);   /* get length of string */
  206.     slashdex = index(tempgx,'/'); /* first occurance of '/' from right */
  207.     colondex = index(tempgx,':');  /* first occurance of ':' from right */
  208.     seploc = 0; /* assumes current dir, no path supplied */
  209.     if slashdex ~= 0 then do /* we assume we are in a DIR */
  210.       seploc = (lengx - slashdex)+1;
  211.       end;
  212.     else do
  213.       if colondex ~= 0 then do /* we assume we are on a device */
  214.         seploc = (lengx - colondex)+1;
  215.         end;
  216.       end;
  217.   gxname = substr(fullnamegx,seploc+1); /* if you ever need it */
  218.   gxpath = left(fullnamegx,seploc);
  219.   return(gxpath);
  220.  
  221. /*
  222.  * Since this script can't be expected to know where the CD of the user
  223.  * is when this cmd is invoked, we have to check the path the user
  224.  * provides - if it's not specified right from a root, then we have
  225.  * to make it a complete specification from the root.
  226.  */
  227. expandfilename:
  228.   parse arg jfile;
  229.   if index(jfile,':') = 0 then do
  230.     curdir = pragma(D);
  231.     if right(curdir,1) ~= ':' then do
  232.       if right(curdir,1) ~= '/' then do
  233.         if curdir ~= '' then do
  234.           curdir = curdir || '/';
  235.           end;
  236.         end;
  237.       end;
  238.     jfile = curdir||jfile;
  239.     end;
  240.   return(jfile);
  241.  
  242. rvalue:
  243.   wordnum = c2d(readch(fhandle,1)) * 256;
  244.   wordnum = wordnum + c2d(readch(fhandle,1));
  245.   return wordnum;
  246.  
  247.